package com.test;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class Main {

	private Logger logger = LogManager.getLogger(Main.class);

	@SuppressWarnings("resource")
	public static void main(String[] args) throws UnknownHostException {
		// on startup
		System.out.println("start");
		long begin = System.currentTimeMillis();
		Settings settings = Settings.builder().put("cluster.name", "jftt").put("client.transport.sniff", "false")
				.build();
		TransportClient client = new PreBuiltTransportClient(settings)
				.addTransportAddress(new TransportAddress(InetAddress.getByName("10.167.27.15"), 9300));
		System.out.println("finish in " + (System.currentTimeMillis() - begin) + " millis");
		System.out.println(client.nodeName());
		GetResponse response = client.prepareGet("test", "_doc", "1").get();
		System.out.println(response.getSourceAsString());
		// on shutdown
		client.close();
	}
}
